package Socket;

import org.w3c.dom.ls.LSOutput;

import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Server3 {

    private ServerSocket serverSocket;
    public Server3(){
        try {
            System.out.println("正在启动服务端...");
            serverSocket=new ServerSocket(8080);
            System.out.println("服务端启动完毕");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    public void start(){
        try {
            System.out.println("等待客户链接...");
            Socket socket=serverSocket.accept();
            System.out.println("一个客户端链接了！");
            InputStream in= socket.getInputStream();
            int len=in.read();
            byte[] data=new byte[len];
            in.read(data);
            String message=new String(data, StandardCharsets.UTF_8);
            System.out.println("客户端发送的数据是："+message);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        Server3 server=new Server3();
        server.start();
    }
}
